define(['jquery','text!../template/news.html','css!../css/news','common'],function($,tplNews){
	let _news = {};
    let currentPage = 1;
	let tpls = {
		'tplNews' :_.template(tplNews)
	};

	_news.show = function(){
        currentPage = 1;
		setTable(0,5);
	}

    function setTable(from,count){
        Ajax('/xjrest/msg/list?from='+from+'&count='+count,setTableBack);
    }

    function reloadTable(){
        currentPage = 1;
        setTable(0,5);
    }

	function setTableBack(data){
        if(data.ret.success){
            let _data = data.ret.value;
            $('#contant').html(tpls.tplNews({message:_data}));

            let totals = data.ret.total;
            if (totals == 0) {
                $("#noRecordMessage").show();
            } else {
                $("#noRecordMessage").hide();
            }
            if (0 == totals % 5) {
                totalPage = parseInt(totals / 5);
                if (totalPage == 0){
                     totalPage = 1;
                }
            } else {
                totalPage = parseInt(totals / 5) + 1;
            }
            $('#pagination').paginations({
                currentPage: currentPage,
                totalPage: totalPage,
                callback: function(current) {
                    currentPage = current;
                    current = (current - 1) * 5;
                    setTable(current,5);
                }
            });
        }
	}

	return _news;
})